package be.ipl.finito.util;

import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;

public final class Util {
	public static void checkObject(final Object o) {
		if (o == null)
			throw new IllegalArgumentException();
	}

	public static void checkString(final String s) {
		checkObject(s);
		if (s.trim().equals(""))
			throw new IllegalArgumentException();
	}

	public static void checkNegativeOrZero(final double d) {
		if (d > 0.0)
			throw new IllegalArgumentException();
	}

	public static void checkPositiveOrZero(final double d) {
		if (d < 0)
			throw new IllegalArgumentException();
	}

	public static void checkPositive(final double d) {
		if (d <= 0.00001)
			throw new IllegalArgumentException();
	}

	public static void checkPositive(final int i) {
		if (i <= 0)
			throw new IllegalArgumentException();
	}
	
	
	public static boolean checkEmail(String email) {
		   boolean result = true;
		   try {
		      InternetAddress emailAddr = new InternetAddress(email);
		      emailAddr.validate();
		   } catch (AddressException ex) {
		      result = false;
		   }
		   return result;
		}
}
